package com.appbee.core.client.startup.links;

import javax.inject.Inject;

import com.appbee.core.client.place.NamedPlace;
import com.appbee.core.client.place.PlaceControl;
import com.appbee.core.client.startup.StartupChain;
import com.appbee.core.client.startup.StartupLink;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.HasWidgets.ForIsWidget;

public class HistoryHandlerStartupLink implements StartupLink
{
	private final EventBus eventBus;
	private final PlaceHistoryHandler historyHandler;
	private final PlaceControl placeController;

	@Inject
	public HistoryHandlerStartupLink(	EventBus eventBus,
								PlaceHistoryHandler historyHandler,
										PlaceControl placeController)
	{
		this.eventBus = eventBus;
		this.historyHandler = historyHandler;
		this.placeController = placeController;
	}

	@Override
	public void start(ForIsWidget container, StartupChain chain)
	{

		chain.start(container);
		// Register placeControler with default place.
		historyHandler.register(placeController, eventBus, new NamedPlace(""));

		// Goes to the place represented on URL else default place
		historyHandler.handleCurrentHistory();

	}

}
